# Contributor: Mike Crute <mike@crute.us>
# Maintainer: Mike Crute <mike@crute.us>
pkgname=gerbera
pkgver=1.12.1
pkgrel=4
pkgdesc="A UPnP Media Server"
url="https://gerbera.io/"
# it fails endianness ip-range comparison tests, on code inside the actual
# program, so it's broken on big-endian
arch="all !s390x"
license="GPL-2.0-or-later"
makedepends="
	cmake
	samurai
	curl-dev
	duktape-dev
	e2fsprogs-dev
	exiv2-dev
	ffmpeg-dev
	ffmpegthumbnailer-dev
	file-dev
	fmt-dev
	gnu-libiconv-dev
	gtest-dev
	inotify-tools-dev
	libebml-dev
	libexif-dev
	libmatroska-dev
	libupnp-dev
	pugixml-dev
	spdlog-dev
	sqlite-dev
	taglib-dev
	zlib-dev
	"
checkdepends="gtest-dev"
install="$pkgname.pre-install"
subpackages="$pkgname-doc $pkgname-openrc"
pkgusers="$pkgname"
pkggroups="$pkgname"
#
# Patches
#
# disable-git-test.patch:
#	Patch removes check for git info in server version output. This assumes
#	that the binary was built within a git repo which is not the case for
#	releases. This test will never work for us.
#
source="gerbera-$pkgver.tar.gz::https://github.com/gerbera/gerbera/archive/v$pkgver.tar.gz
	disable-git-test.patch
	$pkgname-$pkgver-fmt10.patch::https://github.com/gerbera/gerbera/commit/d7123f37b8fde694946ee2d585c3ac961f2e19b4.patch
	$pkgname.initd
	$pkgname.confd"

build() {
	cmake -B build -G Ninja \
		-Wno-dev \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DWITH_MAGIC=1 \
		-DWITH_MYSQL=0 \
		-DWITH_CURL=1 \
		-DWITH_INOTIFY=1 \
		-DWITH_JS=1 \
		-DWITH_TAGLIB=1 \
		-DWITH_AVCODEC=1 \
		-DWITH_FFMPEGTHUMBNAILER=1 \
		-DWITH_EXIF=1 \
		-DWITH_EXIV2=1 \
		-DWITH_MATROSKA=1 \
		-DWITH_SYSTEMD=0 \
		-DWITH_LASTFM=0 \
		-DWITH_DEBUG=0 \
		-DWITH_TESTS=1
	cmake --build build
}

check() {
	cd build
	CTEST_OUTPUT_ON_FAILURE=TRUE ctest
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	"$builddir/build"/gerbera --create-config > config.xml
	sed -i 's#<home>.*#<home>/var/lib/gerbera</home>#' config.xml

	install -dm750 -o $pkgusers -g $pkggroups \
		"$pkgdir/var/lib/$pkgname" \
		"$pkgdir/var/log/$pkgname" \
		"$pkgdir/etc/$pkgname"
	install -m755 -D "$srcdir/$pkgname.initd" \
		"$pkgdir/etc/init.d/$pkgname"
	install -m644 -D "$srcdir/$pkgname.confd" \
		"$pkgdir/etc/conf.d/$pkgname"
	install -m644 -D "config.xml" \
		"$pkgdir/etc/$pkgname/config.xml"
}

sha512sums="
54f4b9fe38f4890d1cac16d433bd70cb2892f3659fffcd5f52814d2f9377c4a8eb68deb3a13053531609727f7ae6cb5ee12bbf652bc41dd1eabd83e6f8dcc1f2  gerbera-1.12.1.tar.gz
5f084b107a534e8d8debda6fbc494ed7ab5d38e6de3d85867f2c316bd3f7d56daf3755de2647be84ae514905f998dad83ac88736a6ca59a30560c3d7a98dffcb  disable-git-test.patch
baf7e60c5ad4f69fa4d1daafefbe3ed317b425b2c0849d93cceb6bb4b73fb3ef714c773868b2b8ad7d300c3a1ae04402211e0be0856bf1bd3caf779de1089db8  gerbera-1.12.1-fmt10.patch
b8609b8ec46d8e61087b76ea9be34639786014f6545a2eb8dae977e56dcc3841715c0691417382d93d96eefd4c5a629e46cd9605c893445a66ac2815ec141c2b  gerbera.initd
392d7e964b0328778847f871e88ffd475ddac99b6cf8c8ded4825eb2f970e084db692552790a1b30ff96f59eabcd9fff50164d9dedf328badab95a1cec833c02  gerbera.confd
"
